package com.iclient.dao.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iclient.dao.ext.PageModel;
import com.iclient.dao.mapper.SinaWbUserMapper;
import com.iclient.dao.model.SinaWbUser;
import com.iclient.dao.service.SinaWbUserService;


@Service("sinaWbUserService")
public class SinaWbUserServiceImpl implements SinaWbUserService{
	
	@Autowired
	private SinaWbUserMapper sinaWbUserMapper;

	@Override
	public void addSinaUser(SinaWbUser user) {
		if(null != sinaWbUserMapper.findByUserId(user.getUserid()))
			return;
		sinaWbUserMapper.insert(user);
	}

	@Override
	public List<SinaWbUser> findUnFollowUsers() {
		return sinaWbUserMapper.findUnFollowUsers();
	}

	@Override
	public PageModel<SinaWbUser> findByPage(Integer page, Integer rows) {
		Integer size = sinaWbUserMapper.findSizeBy(null);
		Map<String, Object> map = new HashMap<>();
		map.put("start", (page-1)*rows);
		map.put("pageSize", rows);
		List<SinaWbUser> list = sinaWbUserMapper.findListByPage(map);
		PageModel<SinaWbUser> pageModel = new PageModel<>();
		pageModel.setRows(list);
		pageModel.setTotal(size);
		pageModel.setPage(page);
		pageModel.setPageSize(rows);
		return pageModel; 
	}

}
